package com.malty.mall.domain.dto.req.pms;


import com.malty.mall.domain.entity.pms.PmsBrand;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import java.util.ArrayList;
import java.util.List;

/**
 * @author malty
 */
@Data
@NoArgsConstructor
@ApiModel("品牌信息")
public class PmsBrandParam {
    private Long id;
    @ApiModelProperty("品牌名称")
    @NotEmpty(message = "name 不能为空")
    private String name;
    @ApiModelProperty("品牌首字母")
    @NotEmpty(message = "firstLetter 不能为空")
    private String firstLetter;
    @ApiModelProperty("排序")
    private Integer sort;
    @ApiModelProperty("品牌制造商")
    private Integer factoryStatus;
    @ApiModelProperty("展示状态")
    @Min(value = 0, message = "最小值0")
    @Max(value = 1, message = "最大值1")
    private Integer showStatus;
    @ApiModelProperty("商品数量")
    @Min(value = 0, message = "最小值0")
    private Integer productCount;
    @ApiModelProperty("商品评论数量")
    @Min(value = 0, message = "最小值0")
    private Integer productCommentCount;
    @ApiModelProperty("品牌图片")
    @NotEmpty(message = "bannerPic 不能为空")
    private String bannerPic;
    @ApiModelProperty("品牌logo")
    @NotEmpty(message = "logo 不能为空")
    private String logo;
    @ApiModelProperty("品牌描述")
    @NotEmpty(message = "description 不能为空")
    private String description;

    public PmsBrandParam(PmsBrand pmsBrand) {
        BeanUtils.copyProperties(pmsBrand, this);
    }

    public static List<PmsBrandParam> brandParams(List<PmsBrand> pmsBrands) {
        List<PmsBrandParam> brandParams = new ArrayList<>();
        for (PmsBrand pmsBrand : pmsBrands) {
            brandParams.add(new PmsBrandParam(pmsBrand));
        }
        return brandParams;
    }
}
